home *** CD-ROM | disk | FTP | other *** search
/ Adobe Graphics & Publishing SDK 1996 December / Adobe Graphics & Publishing SDK 1996 December.iso / mac / Premiere 4.2 SDK r3 Mac / Examples / Projects / Backwards [Audio] / Backwards [Audio].c < prev    next >
Encoding:
Text File  |  1996-01-25  |  3.6 KB  |  103 lines  |  [TEXT/CWIE]

  1. //========================================================================================
  2. //
  3. // Backwards [Audio].c - Backwards audio filter
  4. //
  5. // Written by Randy Ubillos and Bryan K. "Beaker" Ressler.
  6. //
  7. // Copyright ⌐ 1993-96, Adobe Systems Incorporated, all rights reserved worldwide.
  8. //
  9. // Version    1.00    10/20/93    Original version.
  10. // Version    1.01    9/12/94        Updated for 4.0.
  11. // Version  1.02    10/6/95     Updated for 4.2 and CW7.
  12. //
  13. //========================================================================================
  14.  
  15. //========================================================================================
  16. // Includes - use precompiled headers if compiling with CodeWarrior.
  17. //========================================================================================
  18. #ifdef __MWERKS__
  19.     #ifdef powerc
  20.         #include "PremierePPC"
  21.     #else
  22.         #include "Premiere68k"
  23.     #endif
  24. #else
  25.     #include "Premiere.h"
  26. #endif
  27.  
  28. //========================================================================================
  29. // Perform the effect
  30. //========================================================================================
  31. pascal short main (short selector, AudioFilter theData)
  32. {
  33.     short            result = 0, flags;
  34.     unsigned char    *dest, *buff;            // Byte-sized pointers
  35.     unsigned short    *wDest, *wBuff;            // Word-sized pointers
  36.     unsigned long    *lDest, *lBuff;            // Long-sized pointers
  37.     long            count, i, sample;
  38.     char            err;
  39.  
  40.     // Act according to the selector
  41.     switch (selector) {
  42.         case fsExecute:
  43.             // Cache up some values into local storage
  44.             flags = (*theData)->flags;
  45.             dest = (unsigned char *)(*theData)->destination;
  46.             count = (*theData)->samplecount;
  47.             
  48.             // Calculate location from which we should retrieve samples
  49.             sample = (*theData)->totalsamples - count - (*theData)->samplenum;
  50.             
  51.             // Is it okay to call back for samples?
  52.             if ((*theData)->callBack) {
  53.                 // We're in a situation where we can call back to get audio from another
  54.                 // point in time via the callBack parameter of theData. So, make some
  55.                 // space for the samples we're about to receive.
  56.                 if (buff = (unsigned char *)NewPtr(count)) {
  57.                     // Use the callback to retrieve the sound data for the sample offset
  58.                     // we calculated above.
  59.                     err = ((*theData)->callBack)(sample, count, (Ptr)buff,
  60.                         (*theData)->privateData);
  61.                     
  62.                     if (!err) {
  63.                         // We succeeded in getting a buffer-full of samples from the
  64.                         // "opposite" point in time. The samples in this buffer are,
  65.                         // however, not yet backwards. So, reverse the sample order
  66.                         // while copying the samples into the destination buffer.
  67.                         
  68.                         if ((flags & ga16Bit) && (flags & gaStereo)) {
  69.                             // 16-bit stereo (move a long at a time)
  70.                             lDest = (unsigned long *)dest;
  71.                             lBuff = (unsigned long *)buff;
  72.                             count >>= 2;
  73.                             for (i = 0; i < count; i++)
  74.                                 lDest[i] = lBuff[count - i - 1];
  75.                         } else if (flags & (ga16Bit + gaStereo)) {
  76.                             // 16-bit eor stereo (move a word at a time)
  77.                             wDest = (unsigned short *)dest;
  78.                             wBuff = (unsigned short *)buff;
  79.                             count >>= 1;
  80.                             for (i = 0; i < count; i++)
  81.                                 wDest[i] = wBuff[count - i - 1];
  82.                         } else {
  83.                             // 8-bit mono (move a byte at a time)
  84.                             for (i = 0; i < count; i++)
  85.                                 dest[i] = buff[count - i - 1];
  86.                         }
  87.                     }
  88.                     
  89.                     // Lose our temporary buffer
  90.                     DisposPtr((Ptr)buff);
  91.                 }
  92.             } else {
  93.                 // For whatever reason, callbacks to get sound from other points in time
  94.                 // are not allowed right now. So, just punt and copy the samples for the
  95.                 // current point in time to the destination buffer.
  96.                 BlockMove((*theData)->source, dest, count);
  97.             }
  98.             break;
  99.     }
  100.     return(result);
  101. }
  102.  
  103.